<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../../../../../../万能初始化代码/AJax-axios/axios.js"></script>
</head>

<body>
    <form action="">
        用户名: <input type="text" name="username"><br><br>
        密&emsp;码: <input type="text" name="password"><br><br>
        年&emsp;龄: <input type="text"><br><br>
        <input type="submit"><br><br>
    </form>
    <script>
        let fd1 = new FormData();
        fd1.append("name", "张三");
        fd1.append("age", 18);
        console.log(...fd1);
        let form = document.querySelector("form");
        form.addEventListener("submit", function (e) {
            // 阻止默认提交
            e.preventDefault();
            // let fd2 = new FormData(form)
            // console.log(...fd2);
            axios.post("http://www.liulongbin.top:3009/api/formdata", fd1).then(({
                data: res
            }) => {
                console.log(res);
            })
        })
    </script>
</body>

</html>